//
//  UILabel+LableAnimal.m
//  CNKICommunity
//
//  Created by wei on 17/2/27.
//  Copyright © 2017年 CNKI. All rights reserved.
//

#import "UILabel+LableAnimal.h"

@implementation UILabel (LableAnimal)

-(void)labelAnimal:(NSInteger)duration
{
    CABasicAnimation *postAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
    postAnimation.fromValue =@(self.centerY);
    postAnimation.toValue =@(self.centerY - 20);
    postAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0f];
    opacityAnimation.toValue = [NSNumber numberWithFloat:0.0f];
    
    
    CAAnimationGroup *animalGroup = [CAAnimationGroup animation];
    animalGroup.duration = duration;
    animalGroup.fillMode = kCAFillModeForwards;
    animalGroup.removedOnCompletion = NO;
    animalGroup.delegate = self;
    animalGroup.animations = @[postAnimation,opacityAnimation];
    
    [self.layer addAnimation:animalGroup forKey:@"Animation"];
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSLog(@"动画执行完了");
    [self removeFromSuperview];
}



@end
